package com.hjqjl.whdemo.feature.feature0.ui.activity.list.recyclerview;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;

import com.hjqjl.whdemo.base.BaseActivity;
import com.hjqjl.whdemo.databinding.ActivityFruitlistBinding;
import com.hjqjl.whdemo.feature.feature0.adapter.FruitAdapter;
import com.hjqjl.whdemo.feature.feature0.adapter.FruitAdapter2;
import com.hjqjl.whdemo.feature.feature0.ui.activity.list.recyclerview.model.FruitModel;

public class FruitListActivity extends BaseActivity {
    public static void start(Context context) {
        Intent starter = new Intent(context, FruitListActivity.class);
        context.startActivity(starter);
    }

    private int count = 1;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ActivityFruitlistBinding binding = ActivityFruitlistBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());

        LinearLayoutManager layoutManager = new LinearLayoutManager(this);
        binding.homeRvFruitList.setLayoutManager(layoutManager);
//        FruitAdapter adapter = new FruitAdapter(FruitModel.getData());
        FruitAdapter2 adapter = new FruitAdapter2(FruitModel.getData());
        binding.homeRvFruitList.setAdapter(adapter);
        binding.homeTvFruitListRvType.setText("垂直LinearLayoutManager");

        //切换RecyclerView的布局样式
        binding.homeBtnFruitListChangeRv.setOnClickListener(v -> {
            count++;
            if (count == 1) {
                LinearLayoutManager layoutManager1 = new LinearLayoutManager(this);
                layoutManager1.setOrientation(LinearLayoutManager.VERTICAL);
                binding.homeRvFruitList.setLayoutManager(layoutManager1);
                binding.homeTvFruitListRvType.setText("垂直线性布局LinearLayoutManager");
            } else if (count == 2) {
                LinearLayoutManager layoutManager2 = new LinearLayoutManager(this);
                layoutManager2.setOrientation(LinearLayoutManager.HORIZONTAL);
                binding.homeRvFruitList.setLayoutManager(layoutManager2);
                binding.homeTvFruitListRvType.setText("水平线性布局LinearLayoutManager");
            } else if (count == 3) {
                GridLayoutManager layoutManager3 = new GridLayoutManager(this, 3);
                binding.homeRvFruitList.setLayoutManager(layoutManager3);
                binding.homeTvFruitListRvType.setText("网格布局GridLayoutManager");
            } else if (count == 4) {
                StaggeredGridLayoutManager layoutManager4 = new StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.VERTICAL);
                binding.homeRvFruitList.setLayoutManager(layoutManager4);
                binding.homeTvFruitListRvType.setText("垂直瀑布流StaggeredGridLayoutManager");
            } else if (count == 5) {
                StaggeredGridLayoutManager layoutManager5 = new StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.HORIZONTAL);
                binding.homeRvFruitList.setLayoutManager(layoutManager5);
                binding.homeTvFruitListRvType.setText("水平瀑布流StaggeredGridLayoutManager");
                count = 0;
            }
        });
    }
}
